var e = {
    setDefaultUrl: function (e) {
        this.url = e;
    },
    setDefaultParams: function (e) {
        this.defaultParams = e;
    },
    createHttp: function (e, t) {
        var n = cc.loader.getXMLHttpRequest();
        return n.responseType = e, n.timeout = t, n;
    },
    onResponseCallback: function (e, t, n, o) {
        if (4 == e.readyState) if (200 == e.status) {
            Global.config.isDebug;
            var i = null;
            try {
                i = JSON.parse(e.responseText);
            } catch (e) {
                return void (n && n());
            }
            t && t(i);
        } else n && n(0);
    },
    methodByUrl: function (e, t, n, o, i, a, r, s, l) {
        var c = 5e3;
        l && l > 5e3 && (c = l);
        var d = this.createHttp("", c), u = this;
        d.onreadystatechange = function () {
            cc.isValid(r) || void 0 === r ? u.onResponseCallback(d, o, i, s) : cc.log("HttpService onreadystatechange node is null.", r);
        }, d.onerror = function () {
            cc.log("HttpService", "onerror"), i && (cc.isValid(r) || void 0 === r) && i(1);
        }, d.ontimeout = function () {
            cc.log("HttpService", "ontimeout"), i && (cc.isValid(r) || void 0 === r) && i(2);
        };
        var h = t + "?";
        if (a) for (var f in this.defaultParams) this.defaultParams.hasOwnProperty(f) && (h += f + "=" + this.defaultParams[f] + "&");
        if (n) {
            for (var f in n) n.hasOwnProperty(f) && (h += f + "=" + n[f] + "&");
            h = h.substring(0, h.length - 1);
        }
        return Global.config.isDebug && console.log("HttpService url:", h), d.open(e, h, !0),
            d.send(), d;
    },
    postMethodByUrl: function (e, t, n, o, i, a, r, s) {
        this.methodByUrl("POST", e, t, n, o, i, a, r, s);
    },
    postMethod: function (e, t, n, o, i, a) {
        this.postMethodByUrl(this.url, e, t, n, !0, o, i, a);
    },
    getMethodByUrl: function (e, t, n, o, i, a) {
        this.methodByUrl("GET", e, t, n, o, i, a);
    },
    getMethod: function (e, t, n, o) {
        this.getMethodByUrl(this.url, e, t, n, !0, o);
    }
};
window.HttpService = e;
